﻿@model ProductOverviewModel
@using iTextSharp.text.pdf.qrcode
@using Microsoft.Ajax.Utilities
@using Nop.Web.Models.Catalog;
@{
    //prepare "Add to cart" AJAX link
    string addtocartlink = "";
    if (Model.ProductPrice.ForceRedirectionAfterAddingToCart)
    {
        addtocartlink = Url.RouteUrl("AddProductToCart", new { productId = Model.Id, forceredirection = Model.ProductPrice.ForceRedirectionAfterAddingToCart });
    }
    else
    {
        addtocartlink = Url.RouteUrl("AddProductToCart", new { productId = Model.Id });
    }
    var random = new Random();
    var randomInt = random.Next(900000 * Model.Id) + Model.Id;
}
<div class="product-box product-item @if (ViewData["HasSide"] != null && (bool)ViewData["HasSide"] == true) {<text>col-xs-12 col-ms-6 col-sm-4 col-md-4 col-lg-4 col-xl-3</text>} else {<text>col-xs-12 col-ms-4 col-sm-4 col-md-3 col-lg-3 col-xl-2</text>}" data-productid="@Model.Id">
    <div class="product-wrapper">

        <a href="@Url.RouteUrl("Product", new { SeName = Model.SeName })" title="@Model.DefaultPictureModel.Title">
            <div class="image">
                <div class="image-wrapper">
                    <img class="img-responsive" alt="@Model.DefaultPictureModel.AlternateText" src="@Model.DefaultPictureModel.ImageUrl" title="@Model.DefaultPictureModel.Title" />
                </div>
                @if (Model.OutOfStock)
                {
                    <div class="sold-out-bg">
                        <div class="btn btn-red sold-out-display">Sold Out</div>
                    </div>
                }
            </div>

            <div class="product-title">
                <table>
                    <tr>
                        <td>
                            <h4>
                                @Model.Name
                        </h4>
                    </td>
                </tr>
            </table>
        </div>
        
    </a>

    @if (!Model.OutOfStock)
    {
        <div class="free-shipping-icon">
            
        </div>
        <button type="button" class="btn btn-red quick-view-button" data-toggle="modal" data-target="#@randomInt-@Model.Id">
            Quick View
        </button>
    }
    <div class="info">

        <div class="prices">
            @*@if (!String.IsNullOrEmpty(Model.ProductPrice.OldPrice))
                {
                    <div class="old-product-price">
                        <span class="price">WAS @Model.ProductPrice.OldPrice</span>
                    </div>
                }*@
            @*@if (!isLogin)
                {*@
            @if (Model.ProductReview != null && Model.ProductReview.RatingAverage >= 0)
            {

                @Html.Partial("_ProductReviewStars", new ProductReviewStarsModel()
                    {
                        ShowCount = false,
                        RatingPercent = (decimal)Model.ProductReview.RatingAverage * 100 / 5
                    })
            }
            else
            {
                @Html.Partial("_ProductReviewStars", new ProductReviewStarsModel()
                    {
                        ShowCount = false,
                        RatingPercent = 0
                    })
            }
            @if (Model.ProductPrice.IsMembeTier && !String.IsNullOrEmpty(Model.ProductPrice.MemberTierPrice))
            {
                <div class="normal-price">Regular: @Model.ProductPrice.Price</div>
                <div class="highlight-price member-price"><strong>@Model.ProductPrice.MemberTierPrice</strong></div>
            }
            else
            {
                if (!String.IsNullOrEmpty(Model.ProductPrice.MemberTierPrice)){<div class="normal-price member-price">Member: @Model.ProductPrice.MemberTierPrice</div>}
                <div class="highlight-price"><strong>@Model.ProductPrice.Price</strong></div>
            }


            @*}
                else
                {
                    <div class="product-price">
                        <span class="price">@Model.ProductPrice.Price</span>
                    </div>
                }*@

        </div>
    </div>

</div>
@if (!Model.OutOfStock)
{
    <div class="modal fade quick-view-modal shake-modal" id="@randomInt-@Model.Id" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true"><i class="fa fa-times"></i></span></button>
                </div>
                <div class="modal-body">
                    <div class="modal-body-left col-md-6">
                        <div class="image">
                            <a href="@Url.RouteUrl("Product", new { SeName = Model.SeName })">
                                <img class="img-responsive" alt="@Model.DefaultPictureModel.AlternateText" src="@Model.DefaultPictureModel.ImageUrl" title="@Model.DefaultPictureModel.Title" />
                            </a>
                        </div>
                        
                    </div>
                    <div class="modal-body-right col-md-6">
                        <div class="product-header">
                            <h4 class="product-box-title"><a href="@Url.RouteUrl("Product", new { SeName = Model.SeName })">@Model.Name</a></h4>
                            @if (Model.ProductReview != null && Model.ProductReview.RatingAverage >= 0)
                            {

                                @Html.Partial("_ProductReviewStars", new ProductReviewStarsModel()
                                    {
                                        ShowCount = false,
                                        RatingPercent = (decimal)Model.ProductReview.RatingAverage * 100 / 5
                                    })
                            }
                            else
                            {
                                @Html.Partial("_ProductReviewStars", new ProductReviewStarsModel()
                                    {
                                        ShowCount = false,
                                        RatingPercent = 0
                                    })
                            }
                        </div>
                        <div class="free-shipping-product-icon">

                        </div>
                        <div class="prices-summary">
                            @if (!String.IsNullOrEmpty(Model.ProductPrice.MemberTierPrice) && Model.ProductPrice.IsMembeTier)
                            {
                                <span class="current">@Model.ProductPrice.MemberTierPrice</span>
                                <span class="regular">Regular: @Model.ProductPrice.Price</span><br />
                                <span class="save">You save: @Model.ProductPrice.SavePrice (@Model.ProductPrice.SavePercentage)</span>
                            }
                            else
                            {
                                <span class="current">@Model.ProductPrice.Price</span>
                                if (!String.IsNullOrEmpty(Model.ProductPrice.MemberTierPrice))
                                {
                                    <span class="member">Club Member: @Model.ProductPrice.MemberTierPrice</span><br />
                                    <span class="save">You could save: @Model.ProductPrice.SavePrice (@Model.ProductPrice.SavePercentage)</span>
                                }
                                if (!String.IsNullOrEmpty(Model.ProductPrice.OldPrice))
                                {
                                    <span class="old">Was: @Model.ProductPrice.OldPrice</span>
                                }
                            }
                        </div>
                        @*<div class="shipping-message">FREE Shipping!</div>*@
                        <div class="product-box-short-description">
                            @Model.ShortDescription
                        </div>
                        <div class="product-box-price">
                            <div class="price-title">Price</div>
                            <div class="tier-pricing-container">
                                @if (!String.IsNullOrEmpty(Model.ProductPrice.MemberTierPrice) && Model.ProductPrice.IsMembeTier)
                                {
                                    <div class="tier-pricing-table text-center member-tier">
                                        <div class="price-tier member">
                                            <div class="tier-name">Member</div>
                                            <div class="tier-price">@Model.ProductPrice.MemberTierPrice</div>
                                        </div>
                                        <div class="price-tier regular">
                                            <div class="tier-name">Regular</div>
                                            <div class="tier-price">@Model.ProductPrice.Price</div>
                                        </div>
                                    </div>
                                }
                                else
                                {
                                    <div class="tier-pricing-table text-center">
                                        <div class="price-tier regular">
                                            <div class="tier-name">Regular</div>
                                            <div class="tier-price">@Model.ProductPrice.Price</div>
                                        </div>
                                        @if (!String.IsNullOrEmpty(Model.ProductPrice.MemberTierPrice))
                                        {
                                            <div class="price-tier member">
                                                <div class="tier-name">Member</div>
                                                <div class="tier-price">@Model.ProductPrice.MemberTierPrice</div>
                                            </div>
                                        }

                                    </div>
                                }
                                <div class="clear"></div>
                            </div>
                            @if (Model.ProductVariantCount == 1)
                            {
                                <div class="col-xs-6">Quantity</div>
                                <div class="col-xs-6"><input type="number" class="form-control quantity" value="1"></div>
                                <div class="clear"></div>
                            }
                        </div>
                        @if (Model.ProductVariantCount == 1)
                        {
                            <a class="btn btn-danger add-to-cart btn-block" href="javascript:void(0)" onclick="AjaxCart.addproducttocart('@Url.RouteUrl("AddProductToCart", new { productId = Model.Id })', $('#product-details-form'), $(this));return false;">@T("ShoppingCart.AddtoCart")</a>
                            <div class="product-add-loading">
                                <img class="loading-gif" src="/content/images/loading.gif" />
                                <img class="loading-svg" src="/content/images/loading.svg" />
                            </div>
                        }
                        <a class="btn btn-block btn-info more-information-button" href="@Url.RouteUrl("Product", new { SeName = Model.SeName })" title="@Model.DefaultPictureModel.Title">Full Details</a>
                    </div>
                    <div class="clear"></div>
                </div>
                <div class="modal-footer">
                </div>
            </div>
        </div>
    </div>
}
</div>
